<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
	<title>Cadastro de Trecho</title>
</h:head>
<h:body>
	<h:form id="trecho">
		<p:growl id="confirmaTrecho" />
		<p:fieldset legend="Cadastrar Trecho">
			<h:panelGrid columns="1">
				<h:outputLabel value="Selecione Rota:" />
				<p:selectOneMenu id="selecioneRota" value="#{trechoAction.destino}">
					<f:selectItem itemLabel="Selecione" itemValue="" />
					<f:selectItems value="#{trechoAction.listaItemRotas}" />
				</p:selectOneMenu>

				<h:outputLabel value="Selecione o Veiculo:" />
				<p:selectOneMenu id="selecioneVeiculo" value="#{trechoAction.placaPolicial}" >
					<f:selectItem itemLabel="Selecione" itemValue="" />
					<f:selectItems value="#{trechoAction.listaItemVeiculos}" />

				</p:selectOneMenu>

				<h:outputLabel value="Data de Saída:" />
				<p:calendar value="#{trechoAction.trecho.dataSaida}" mode="popup"
					navigator="true" size="08" pattern="dd.MM.yyyy">
				</p:calendar>
			</h:panelGrid>
			<h:panelGrid>


				<h:outputLabel value="Procurar por Nº da NF:" />
				<p:inputText id="inseriNumeroNota"
					value="#{trechoAction.codNotaFiscal}" />
				<p:commandButton id="procurarNtFiscal" value="Incluir"
					update="confirmaTrecho"
					actionListener="#{trechoAction.procurarNotaFiscal}"
					oncomplete=":inserirListaNotaFisca" />

				<p:dataTable id="inserirListaNotaFiscal" var="TabelaTrecho"
					value="#{trechoAction.listaNotaFiscal}"
					emptyMessage="Não encontrada nenhuma Nota Fiscal!">
					<p:column headerText="Codigo da Nota Fiscal">
						<h:outputText value="#{TabelaTrecho.codNotafiscal}" />
					</p:column>
					<p:column headerText="Origem:">
						<h:outputText value="#{TabelaTrecho.localEmissao}" />
					</p:column>
					<p:column headerText="Destino:">
						<h:outputText
							value="#{TabelaTrecho.coletaMercadoria.pessoa.endereco.cidade}" />
					</p:column>
					<p:column headerText="Data de Emissão:">
						<h:outputText value="#{TabelaTrecho.dataEmissao}" />
					</p:column>

					<p:column style="width:100px">
						<h:panelGrid columns="1" styleClass="actions" cellpadding="2" >
							<p:commandButton 
								oncomplete="confirmeAcao.show()" title="Excluir"
								image="ui-icon ui-icon-close">
								<f:setPropertyActionListener value="#{TabelaTrecho}"
									target="#{trechoAction.notaFiscalSelecionada}" />
							</p:commandButton>

						</h:panelGrid>
					</p:column>

				</p:dataTable>

<!-- Confirma Excluir lista -->

				<p:confirmDialog message="Deseja excluir a Notafiscal" modal="true"
					header="Confirme Ação!" widgetVar="confirmeAcao">


					<p:commandButton
						actionListener="#{trechoAction.deletarNotaDaLista}" value="Sim"
						oncomplete="confirmeAcao.hide()" update="inserirListaNotaFiscal"
						title="Gravar" image="ui-icon ui-icon-check" />
					<p:commandButton value="Não" onclick="confirmeAcao.hide()"
						type="button" />


				</p:confirmDialog>

				<p:commandButton value="Gravar" title="Salvar no Banco" oncomplete="salvaTrecho.show()" />
<!-- Confirma salvar trecho -->
				<p:confirmDialog message="Deseja salvar Trecho" modal="true"
					header="Confirme Ação!" widgetVar="salvaTrecho">

					<p:commandButton actionListener="#{trechoAction.salvarTrecho}"
						value="Sim" oncomplete="salvaTrecho.hide()"
						update="confirmaTrecho :trecho" title="Salvar"/>
					<p:commandButton value="Não" onclick="salvaTrecho.hide()"
						type="button" title="Não salvar"/>
				</p:confirmDialog>
			</h:panelGrid>

		</p:fieldset>



	</h:form>
</h:body>


</html>